//
//  JYBaseOrderController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/16.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYBaseOrderController.h"
#import "JYOrderCell.h"
#import "JYOrderModel.h"
#import "JYOrderDetaController.h"

@interface JYBaseOrderController ()
@property(nonatomic)NSMutableArray *dataArr;

@property(nonatomic)NSMutableArray *orderArr;
@end

static NSString *JYOrderCellID = @"JYOrderCellID";
@implementation JYBaseOrderController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupTableView];

    [self loadDataFromNetwork];
}
- (void)setType:(JYOrderType)type{

    _type = type;
    
    [self.tableView reloadData];

}


- (void)loadDataFromNetwork{

    
    
   NSString *orderNumber   = [NSString stringWithFormat:@"订单号%zd",arc4random_uniform(666888123)];
    for (int i = 0; i< 10; i++) {
        
        JYOrderModel *model = [[JYOrderModel alloc]init];
        model.orderType = _type;
        model.orderNumber = [orderNumber integerValue];
        [self.orderArr addObject:model];
    }

    [self.tableView reloadData];

}
- (void)setupTableView{
    
    
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 40, 0);
    self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
    self.tableView.rowHeight = 258;
    [self.tableView registerNib:[UINib nibWithNibName:@"JYOrderCell" bundle:nil] forCellReuseIdentifier:JYOrderCellID];
    
    
}
/*
 JYOrderType_all = 0, // 全部
 JYOrderType_pay = 1,//待付款
 JYOrderType_shipping = 2,//待发货
 JYOrderType_goods = 3,//待收货
 JYOrderType_complete = 4,//已完成
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (_type == JYOrderType_all) {
        return arc4random_uniform(20);
    }else if (_type == JYOrderType_pay){
      return 2;
    }else if (_type ==JYOrderType_shipping){
     return 3;
    }else if (_type == JYOrderType_goods){
    
        return 4;
    }else{
    return 5;
    
    }
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JYOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:JYOrderCellID];
    
    cell.model = [self.orderArr safeObjectAtIndex:indexPath.row];
       cell.collectionView.orderDataArr = @[@"全部",@"待付款",@"待发货",@"待收货",@"已完成",@"全部",@"待付款",@"待发货",@"待收货",@"已完成",@"全部",@"待付款",@"待发货",@"待收货",@"已完成"];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
        JYOrderDetaController *detaVc = [JYOrderDetaController new];
           detaVc.type = _type;
            [self.navigationController pushViewController:detaVc animated:YES];
        

}
- (NSMutableArray *)dataArr{

    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;

}
- (NSMutableArray *)orderArr{

    if (!_orderArr) {
        _orderArr = [NSMutableArray array];
    }

    return _orderArr;
}





@end
